package com.imc.api.user.service;

import com.imc.api.user.tuple.UserTuple;
import com.imc.platform.base.user.dao.mapper.IUserMapper;
import com.imc.platform.base.user.dao.repository.UserRepository;
import com.imc.platform.base.user.pojo.User;
import com.imc.platform.base.user.pojo.UserSub;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.security.Principal;

/**
 * Created by tanweiping on 2018/10/9.
 */
@Service
@Transactional
public class ApiUserService {

    @Autowired
    UserRepository userRepository;
    @Autowired
    IUserMapper userMapper;

    /*
     * YT  2018/10/28 22:10
     * 方法描述：补充用户信息
     */
    public User appendUserMessage(UserTuple userTuple, Principal principal) {
        User user = userRepository.findAllByLoginName(principal.getName());
        if (user == null) return null;
        user.setTrueName(userTuple.getNickName());
        user.setChannel(userTuple.getChannel());
        user.setPhoto(userTuple.getAvatarUrl());
        user.setSex(userTuple.getGender());
        user.setWechatName(userTuple.getNickName());
        user.setCityName(userTuple.getCity());
        return userRepository.save(user);
    }
    
    
    /*
    * tanweiping  2018/11/20 10:12
    * 方法描述：充值
    */
    public void rechange(){

    }

    public void addUserSubaccount(UserSub userSub){
       userMapper.addUserSubaccount(userSub);
    }

    public void updateUserSubaccount(UserSub userSub){
        userMapper.updateUserSub(userSub);
    }

}